package com.itheima.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.Question;
import com.itheima.mapper.QuestionMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class QuestionServiceImpl implements QuestionService {

    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public Question findByUserId(Long userId) {
        // 创建查询对象
        QueryWrapper<Question> qw = new QueryWrapper<>();
        qw.eq("user_id", userId);
        return questionMapper.selectOne(qw);
    }

    @Override
    public void sava(Question question) {
         questionMapper.insert(question);
    }

    @Override
    public void update(Question question) {
        QueryWrapper<Question> qw = new QueryWrapper<>();
        qw.eq("user_id",question.getUserId());
        questionMapper.update(question,qw);

    }
}